package com.jlf.controller.engine.entity.field;

import com.jlf.core.engine.domain.SchemaFieldDO;
import com.jlf.core.engine.domain.SchemaIndexDO;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * 模型字段的详情输出
 *
 * @author wujr
 * 2023/7/18
 * @version 1.0
 * 【变更历史】
 * [wujr 2023/7/18 1.0 新增]
 */
@Getter
@Setter
public class SchemaFieldDetail extends FieldDetail{
    private String domainCode;
    private List<IndexDetail> indexes;

    public SchemaFieldDetail(SchemaFieldDO record){
        super(record);
        this.domainCode = record.getDomainCode();
    }

    public void addIndex(SchemaIndexDO index, List<String> columns){
        if (this.indexes == null){
            this.indexes = new ArrayList<>();
        }
        this.indexes.add(new IndexDetail(index, columns));
    }

    @Getter
    @Setter
    public static class IndexDetail{
        private Long id;
        private String name;
        private List<String> columns;
        private Integer type;

        public IndexDetail(SchemaIndexDO record, List<String> columns){
            this.id = record.getId();
            this.name = record.getName();
            this.type = record.getType();
            this.columns = columns;
        }
    }
}
